package com.emeraldparser.util;

public class Characters {

	public static String escape(char character) {
		switch (character) {
		case '\r': return "\\r";
		case '\n': return "\\n";
		case '\t': return "\\t";
		case '\\': return "\\\\";
		default:
			return String.valueOf(character);
		}
	}

	public static CharSequence escape(CharSequence charSequence) {
		StringBuilder text = new StringBuilder();
		
		for (int i = 0; i < charSequence.length(); i++) {
			char character = charSequence.charAt(i);
			if (character == '"') {
				text.append("\\\"");
			} else {
				text.append(escape(character));
			}
		}
		
		return text.toString();
	}

}
